package com.tutorial.bf;

import com.tutorial.bf.dao.UserDao;
import com.tutorial.bf.service.UserService;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

public class BeanFactoryTest {
    public static void main(String[] args) {
        // 1、创建一个工厂对象
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        // 2、创建一个读取器（xml文件）
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        // 3、读取配置文件给工厂
        reader.loadBeanDefinitions("ApplicationContext-beans.xml");
        // 4、根据id获取bean对象
        UserService userService = (UserService) beanFactory.getBean("userService");
        // System.out.println("userService = " + userService);
        UserDao userDao = (UserDao) beanFactory.getBean("userDao");
        // System.out.println("userDao = " + userDao);
    }
}
